# from django.db.models.signals import post_save
# from django.dispatch import receiver
# from django.contrib.auth.models import User
# from django.conf import settings
# from rest_framework.decorators import api_view
# from .models import Course, PartMaster
# from .serializers import CourseSerializer, PartMasterSerializer
# from rest_framework.authtoken.models import Token
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
from .qadutil import api_process
from .applog import make_logs


# from .serializers import ApiDataSerializer


class DiscretePo(APIView):
    # 所有API都执行同样的方法如何处理
    def get(self, request):
        data = {"message": "Hello PO"}
        # print(data)
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'purchaseorder/discretepo/'
        # print(linux_access)
        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_201_CREATED)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Itemmaster(APIView):
    def get(self, request):
        data = {"message": "ItemmasterData"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'items/itemmaster/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Unpissrct(APIView):
    def get(self, request):
        data = {"message": "Unplannedissue"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'transactions/Unplannedissue/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Poreceipt(APIView):
    def get(self, request):
        data = {"message": "Poreceipt"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'purchaseorder/discretepo/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Backflush(APIView):
    def get(self, request):
        data = {"message": "Backflush"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'workorder/backflush/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class InTransfer(APIView):
    def get(self, request):
        data = {"message": "InventoryTransfer"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'transactions/intransfer/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class BomMaster(APIView):
    def get(self, request):
        data = {"message": "Bommaster load"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'bom/bommastr/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Loadbommastr(APIView):
    def get(self, request):
        data = {"message": "Bommaster load"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'bom/loadbommastr/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class RoutingDet(APIView):
    def get(self, request):
        data = {"message": "RoutingDetail"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'routing/routingdetail/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class SupplierMaster(APIView):
    def get(self, request):
        data = {"message": "SupplierMaster"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'supplier/exportsupplier/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class PoDetail(APIView):
    def get(self, request):
        data = {"message": "Po Detail"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'puchaseorder/podetexport/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class SoDetail(APIView):
    def get(self, request):
        data = {"message": "So Detail"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'salesorder/salesorderexport/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class CustomerMaster(APIView):
    def get(self, request):
        data = {"message": "CustomerMaster"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'customer/exportcustomer/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class SupplierInvoice(APIView):
    def get(self, request):
        data = {"message": "SupplierInvoice"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'supplierinvoice/createsupplierinvoice/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class SupplierInvoice1(APIView):
    def get(self, request):
        data = {"message": "SupplierInvoice"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'supplierinvoice/createsupplierinvoice/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class QadGrir(APIView):
    def get(self, request):
        data = {"message": "QadGrir"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'qadgrir/qadgrirexport/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class CustRequiredSchedule(APIView):
    def get(self, request):
        data = {"message": "CustReqestSchedule"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'customer/custrequiredschedule/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class SupplierSchedule(APIView):
    def get(self, request):
        data = {"message": "SupplierSchedule"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'supplier/supplierschedule/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class ProductionSchedule(APIView):
    def get(self, request):
        data = {"message": "ProductionSchedule"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'production/productionschedule/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class InventoryDetail(APIView):
    def get(self, request):
        data = {"message": "InventoryDetail"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'inventory/inventorydetail/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Project(APIView):
    def get(self, request):
        data = {"message": "Project"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'project/projectdetail/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Costcenter(APIView):
    def get(self, request):
        data = {"message": "Costcenter"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'costcenter/costcenterdetail/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Cost(APIView):
    def get(self, request):
        data = {"message": "Cost"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'cost/costdetail/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)


class Supplierinvoicebalance(APIView):
    def get(self, request):
        data = {"message": "Supplierinvoicebalance"}
        return Response(data, status=status.HTTP_200_OK)

    def post(self, request):
        uri = r'supplier/supplierinvoicebalance/'

        make_logs("API: " + uri + " start...")
        api_status, api_return_data = api_process(request, uri)
        if api_status:
            return Response(api_return_data, status=status.HTTP_200_OK)
        return Response(api_return_data, status=status.HTTP_400_BAD_REQUEST)
